package com.m.crm.web;

import com.m.crm.dto.BaseResult;
import com.m.crm.service.MailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by yugoh on 2017/5/26.
 */
@RestController
@RequestMapping("/mails")
public class MailController {
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    private final MailService mailService;

    @Autowired
    public MailController(MailService mailService) {
        this.mailService = mailService;
    }

    @RequestMapping(value = "/security/code", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public BaseResult<Object> securityCode(String toAddress) {
        log.info("invoke----------/mails/security/code.get");
        try {
            mailService.sendSecurityCode(toAddress);
        } catch (Exception e) {
            return new BaseResult<>(false, e.getMessage());
        }
        return new BaseResult<>(true, null);
    }
}
